package com.derbysoft.dswitch.adapter.ihg.web.action.admin.setting.freemeal;

import com.derbysoft.dswitch.adapter.ihg.common.domain.ConfigInfo;
import com.derbysoft.dswitch.adapter.ihg.common.domain.FreeMealStrategy;
import com.derbysoft.dswitch.adapter.ihg.common.repository.ConfigRepository;
import com.derbysoft.dswitch.adapter.ihg.common.repository.FreeMealStrategyRepository;
import com.derbysoft.dswitch.adapter.ihg.common.utils.Constants;
import com.derbysoft.dswitch.adapter.ihg.web.action.support.PaginateActionSupport;
import com.opensymphony.xwork2.ActionContext;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.springframework.beans.factory.annotation.Autowired;

public class ListAction extends PaginateActionSupport {
    @Autowired
    private FreeMealStrategyRepository freeMealStrategyRepository;

    @Autowired
    private ConfigRepository configRepository;

    private FreeMealStrategy freeMealStrategy;

    private ConfigInfo configInfo;

    @Action("list")
    public String list() {
        setConfigInfo(configRepository.loadByCode(Constants.KEY_MATCH_PRIORITY));
        ActionContext.getContext().setLocale(ServletActionContext.getRequest().getLocale());
        setPaginater(freeMealStrategyRepository.paginater(freeMealStrategy, getPaginater()));
        return SUCCESS;
    }

    public FreeMealStrategy getFreeMealStrategy() {
        return freeMealStrategy;
    }

    public void setFreeMealStrategy(FreeMealStrategy freeMealStrategy) {
        this.freeMealStrategy = freeMealStrategy;
    }

    public ConfigInfo getConfigInfo() {
        return configInfo;
    }

    public void setConfigInfo(ConfigInfo configInfo) {
        this.configInfo = configInfo;
    }
}
